package feap;

import java.util.ArrayList;

import fem2.AbstractStructuralStaticDemo;
import fem2.Constraint;
import fem2.Element;
import fem2.MaterialModel;
import fem2.Mesh;
import fem2.MeshGenerator;
import fem2.MeshPart;
import fem2.MeshUtilities;
import fem2.Model;
import fem2.Node;
import fem2.element.StructuralElement;
import fem2.enu.State;
import fem2.material.StVenantKirchhoffMM;
import fem2.pre_and_post.PatchMeshGenerator;

/**
 * works correctly
 * 
 * @author hbui
 * 
 */
public class Ipatch extends AbstractStructuralStaticDemo {

	public Ipatch() {
		projectDir = "/home/hbui/kratos_janosch/fem2012-feap-validation";
		projectName = "Ipatch.gid";
		meshFileName = "mesh5x5";
	}

	@Override
	public Mesh createMesh() {
		MeshGenerator mg = new PatchMeshGenerator(6, 6, 0, 0, 0.2, 0.2);
		return mg.getMesh(2);
	}

	@Override
	public Model createConditions(Model m) {
		Mesh mesh = m.getMesh();
		ArrayList<Node> bottom = MeshUtilities.seekNodesOnLine(mesh, 0, 0, 1, 0);
		ArrayList<Node> left = MeshUtilities.seekNodesOnLine(mesh, 0, 0, 0, 1);
		ArrayList<Node> top = MeshUtilities.seekNodesOnLine(mesh, 0, 1, 1, 0);

		Constraint cx = new Constraint(false, true);
		Constraint cy = new Constraint(true, false);

		mesh.addConstraint(cx, left);
		mesh.addConstraint(cy, bottom);

		Constraint cu = new Constraint(true, false);
		cu.setValue(1, -0.1);
		mesh.addConstraint(cu, top);

		return m;
	}

	@Override
	public MaterialModel createMaterial(Model m) {
		double E = 1000.0;
		double nu = 0.25;
		MaterialModel mm = new StVenantKirchhoffMM(E, nu, 1.0, 0.0, State.PLANE_STRAIN);
		return mm;
	}

	@Override
	public Element createElement(MeshPart mp, MaterialModel mm) {
		return new StructuralElement(mp, mm);
	}

	public static void main(String[] args) {
		AbstractStructuralStaticDemo demo = new Ipatch();

		demo.run();
	}
}
